package cn.wolfcode.crm.service.impl;

import java.util.Date;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import cn.wolfcode.crm.domain.Customer;
import cn.wolfcode.crm.domain.CustomerTransfer;
import cn.wolfcode.crm.mapper.CustomerMapper;
import cn.wolfcode.crm.mapper.CustomerTransferMapper;
import cn.wolfcode.crm.query.QueryObject;
import cn.wolfcode.crm.service.ICustomerTransferService;
@Service
public class CustomerTransferServiceImpl implements ICustomerTransferService{

	@Autowired
	private CustomerTransferMapper customerTransferMapper;
	
	@Autowired
	private CustomerMapper customerMapper;

	@Override
	public void save(CustomerTransfer entity) {
		//设置移交人员
		entity.setOperatorId(1L);
		//设置移交时间
		entity.setOperateTime(new Date());
		customerTransferMapper.insert(entity);
		
		//更新当前客户的销售人员
		Customer customer = new Customer();
		customer.setId(entity.getCustomer().getId());
		customer.setSeller_id(entity.getNewSeller().getId());
		customerMapper.update(customer);
		
	}

	@Override
	public CustomerTransfer get(Long id) {
		return customerTransferMapper.selectById(id);
	}

	@Override
	public PageInfo<CustomerTransfer> list(QueryObject qo) { 
		PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
		List<CustomerTransfer> list = customerTransferMapper.selectAll(qo);
		return new PageInfo<>(list);
	}

	@Override
	public List<CustomerTransfer> listNotPage(QueryObject qo) {
		List<CustomerTransfer> list = customerTransferMapper.selectAll(qo);
		return list;
	}

}
